var express = require('express');
var router = express.Router();
const fs = require("fs");
const path = require("path");

// console.log('__dirname', __dirname);
// console.log('__filename', __filename);

fs.readdirSync(__dirname)
    .filter((name) => name !== __filename.slice(__dirname.length + 1))
    .forEach((name) => {
        const route = require(path.join(__dirname, name))
        // console.log(name.replace('.js', ''));
        // console.log(route);
        if (name === 'index.js') {
            router.use('/', route)
        } else {
            router.use('/api/' + name.replace('.js', ''), route)
        }
    });

module.exports = router;


